import { Base } from '../../../utils/base.js'
const app = getApp()
class Order extends Base {
  constructor() {
    super()
  }

  /*创建订单*/
  createOrder(data, callback) {
    let param = {
      url: app.globalData.api + '/api/v1.0/orders/add/' + app.globalData.shop_id,
      data,
      type: 'POST',
      showLoading: true,
      sCallback: (res) => {
        callback && callback(res.data.data)
      }
    }
    this.request(param)
  }

  /*查询最近订单列表*/
  getOrderList(data, callback) {
    let param = {
      url: app.globalData.api + '/api/v1.0/orders/list/' + app.globalData.shop_id + '?page=' + data.page + '&pagesize=' + data.pagesize,
      data,
      sCallback: (res) => {
        callback && callback(res.data.data)
      }
    }
    this.request(param)
  }

  /*查询订单详情*/
  getOrderDetail(data, callback) {
    let param = {
      url: app.globalData.api + '/api/v1.0/orders/detail/' + data['order_id'],
      data,
      sCallback: (res) => {
        callback && callback(res.data.data)
      }
    }
    this.request(param)
  }

  /* 更新订单状态 */
  updateOrderState(data, callback) {
    let param = {
      url: app.globalData.api + '/api/v1.0/orders/edit/' + data['order_id'],
      data,
      type: 'PUT',
      sCallback: (res) => {
        callback && callback(res.data.data)
      }
    }
    this.request(param)
  }
}

export { Order }